﻿using BLL;
using MODEL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Loginter.承运单管理
{
    public partial class CarriersG : System.Web.UI.Page
    {
        CarrierBLL carr = new CarrierBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                getProcCarr();
            }
        }

        #region 查询
        /// <summary>
        /// 存储过程查询
        /// </summary>
        private void getProcCarr()
        {
            int TotalCount;
            string id = txt_carries.Text.Trim();
            string name = txt_Receive.Text;
            string SendName = txt_Send.Text.Trim();
            DateTime? startTime = null;
            if (!string.IsNullOrWhiteSpace(dateinput.Value.Trim()))
            {
                startTime =Convert.ToDateTime(dateinput.Value);
            }
            DateTime? endTime = null;
            if (!string.IsNullOrWhiteSpace(dateinput.Value.Trim()))
            {
                endTime = Convert.ToDateTime(dateinput.Value);
            }
            CarrierMODEL model = new CarrierMODEL()
            {
                Carriersid =id,
                ReceiveLinkman = name,
                SendLinkman = SendName,
                LeaverDate_in = Convert.ToDateTime(startTime),
                LeaverDate_end = Convert.ToDateTime(endTime)
            };
            List<CarrierinfoMODEL> list = carr.GetCarriesList(model);
            repser_carries.DataSource = list;
            repser_carries.DataBind();
        }
        #endregion

        protected void btn_select_Click(object sender, EventArgs e)
        {
            getProcCarr();
        }
        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="src"></param>
        /// <param name="e"></param>
        protected void TruckPager_PageChanging1(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            TruckPager.CurrentPageIndex = e.NewPageIndex;
            getProcCarr();
        }
        protected void repser_carries_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            int id = Convert.ToInt32(e.CommandArgument);
            //更新承运单跳转
            if (e.CommandName == "update")
            {
                // 跳转更新页面 并传递id
                Response.Redirect("UpdateCarries.aspx?id=" + id);
            }
            //删除承运单跳转
            if (e.CommandName == "del")
            {
                //执行删除
                int rest = carr.DelCarriage(id);
                if (rest == -1)
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('该用户已删除');</script>");
                }
                if (rest > 0)
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('删除成功！');</script>");
                    getProcCarr();
                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('删除失败！');</script>");
                }
            }
            //详情跳转
            if (e.CommandName == "select")
            {
                Server.Transfer("CarriersXiangQing.aspx?id=" + id);
            }
            //添加承运单跳转
            if (e.CommandName == "addGoods")
            {
                // 跳转更新页面 并传递id
                Server.Transfer("AddCarriers.aspx?id=" + id);
            }
        }

    }
}